import Cookie from 'js-cookie'

let userInfo = Cookie.get('userInfo') ?JSON.parse(Cookie.get('userInfo')):{};

export default {
    namespaced: true,
    state: {
        name: userInfo.name,
        icon: userInfo.icon,
        token: userInfo.token,
    },
    actions: {},
    mutations: {
        setUserInfo(state, val) {
            state.name = val.name
            state.icon = val.icon
            state.token = val.token
            Cookie.set('userInfo', JSON.stringify(val))
        },
        clearUserInfo(state) {
            state.name = ''
            state.icon = ''
            state.token = ''
            Cookie.remove('userInfo')
        },
    },
    getters: {
        userInfo(state){
            return {
                name:state.name,
                icon:state.icon,
                token:state.token
            }
        }
    }

}
